﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using GameCore;
using GameObject;
using ResourceManager;
using HandlingInput;

namespace ManagerGameState
{
    public class GameMain: GameState
    {
        public GameMain()
        {
            this.GAME_STATE_DEF = (int)GSID.GameSateID.GAME_STATE_MAIN;
        }

        NaviBoard na;
        Map map;
        Stone stone;
        House house;
        protected override void Enter(GameTime gameTime)
        {
            ManagerDefine.Init();

            ActionBoard a = (ActionBoard)ManagerDefine.MActionBoard.CreateObject(0);
            List<ActionButton> l_abt = new List<ActionButton>();
            ActionButton bt1 = (ActionButton)ManagerDefine.MActionButton.CreateObject(0);
            bt1.Enter += new Window.GetEvent(bt1_Enter);
            l_abt.Add(bt1);
            l_abt.Add((ActionButton)ManagerDefine.MActionButton.CreateObject(0));
            l_abt.Add((ActionButton)ManagerDefine.MActionButton.CreateObject(0));
            l_abt.Add((ActionButton)ManagerDefine.MActionButton.CreateObject(0));
            a.AddAction(l_abt);

            na = (NaviBoard)ManagerDefine.MNaviBoard.CreateObject(0);
            na.setActionBoard(a);
            ViewFrame.Lock = false;


            map = (Map)ManagerDefine.MMap.CreateObject(0);
            stone = (Stone)ManagerDefine.MStone.CreateObject(0);

            house = (House)ManagerDefine.MHouse.CreateObject(0);
        }

        void bt1_Enter(Window window, GameState gs)
        {
            ((ActionButton)window).Active_Wait(100);
        }
        protected override void Update(GameTime gameTime)
        {
            ViewFrame.update(new Point(EventHandle._currentMouse.X, EventHandle._currentMouse.Y));

            na.Update(gameTime, 0, ViewFrame.window.Height - ViewFrame.window.Width / 6, ViewFrame.window.Width, ViewFrame.window.Width / 6);
            map.Update(gameTime);
            stone.Update(gameTime, 100, 100, ResourceDefine.Map_cellWidth, ResourceDefine.Map_cellHeight);
            house.Update(gameTime, 200, 100, 500, 250);
        }
        protected override void Render(GameTime gameTime, SpriteBatch g_DC)
        {
            g_DC.GraphicsDevice.Clear(Color.Black);
            map.Draw(gameTime, g_DC);
            stone.Draw(gameTime, g_DC);
            house.Draw(gameTime, g_DC);
            na.Draw(gameTime, g_DC);    
        }
        protected override void RenderEnter(GameTime gameTime, SpriteBatch g_DC)
        {
            g_DC.GraphicsDevice.Clear(Color.Wheat);
        }

    }
}
